package ace.module.account.core.impl.manager;

import ace.module.account.api.enums.IamAccountPassportPassportTypeEnum;
import ace.module.account.api.model.dto.IamAccountPassportDto;
import ace.module.account.api.model.input.passport.IamAccountPassportFilterInput;
import ace.module.account.core.impl.dao.entity.IamAccount;
import ace.module.account.core.impl.dao.entity.IamAccountPassport;
import ace.module.common.core.impl.manager.EntityOfAppManager;
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

/**
 * @author caspar
 * @date 2023/3/20 9:28
 */
public interface IamAccountPassportManager extends EntityOfAppManager<IamAccountPassport, Long, IamAccountPassportDto> {

  IamAccountPassport getByIamAppIdAndTagAndPassportAndPassportType(
      Long iamAppId, String tag, String passport, Integer passportType);

  List<IamAccountPassport> getByIamAppIdAndTagAndPassportAndPassportTypes(
      Long iamAppId, String tag, String passport, List<Integer> passportTypes);

  List<Long> getAccountIdByIamAppIdAndTagAndPassportAndPassportTypes(
      Long iamAppId, String tag, String passport, List<Integer> passportTypes);

  IamAccountPassport getByIamAppIdAndTagAndPassportAndPassport2AndPassport3AndPassportType(
      Long iamAppId,
      String tag,
      String passport,
      String passport2,
      String passport3,
      Integer passportType);

  List<IamAccountPassport> getByIamAppIdAndTagAndPassportAndPassportTypes(
      Long iamAppId, String passport, List<Integer> passportTypes);

  /**
   * @param iamAccountIdList account id
   * @return key=accountId value=手机号码
   */
  Map<Long, String> getPhonePassportMapByAccountId(List<Long> iamAccountIdList);

  Page<IamAccountPassportDto> search(Long iamAppId, @Nullable IamAccountPassportFilterInput filter, Pageable pageable);

  Map<Long, IamAccountPassport> getPhonePassportEntityMapByIamAccountIdIn(List<Long> iamAccountIdList);

  /**
   * @param iamAccountIdList account id
   * @return key=accountId value={@link IamAccountPassport}
   */
  Map<Long, IamAccountPassport> getPhonePassportEntityMapByIamAccountIdIn(Long iamAppId, List<Long> iamAccountIdList);

  List<IamAccountPassport> getPhonePassportByIamAccountIdIn(List<Long> iamAccountIdList);

  List<IamAccountPassport> getPhonePassportByIamAccountIdIn(Long iamAppId, List<Long> iamAccountIdList);

  IamAccountPassport getPhonePassportByIamAccountId(Long iamAppId, Long iamAccountId);

  Map<Long, IamAccountPassportDto> getAccountIdAndUsernamePassportDtoMapByAccountId(List<Long> iamAccountIds);

  Map<Long, IamAccountPassportDto> getIamAccountIdAndPassportDtoMapByIamAccountIdAndPassportType(
      List<Long> iamAccountIds,
      IamAccountPassportPassportTypeEnum passportPassportTypeEnum
  );

  Map<Long, IamAccountPassport> getIamAccountIdAndPassportMapByIamAccountIdAndPassportType(
      List<Long> iamAccountIds,
      IamAccountPassportPassportTypeEnum passportPassportTypeEnum
  );

  IamAccountPassport getUsernamePassportByIamAccountId(Long iamAccountId);

  Map<Long, IamAccountPassportDto> getAccountIdAndPhonePassportDtoMapByAccountId(List<Long> iamAccountIds);

  void checkExistsWxMiniAppIdAndOpenId(Long iamAppId, String wxMiniAppId, String openId);

  void checkExistsPhoneNumber(Long iamAppId, String phoneNumber);

  void checkExistsByUserName(Long iamAppId, String username);

  /**
   * 创建账户名通行证对象,没有落库.
   *
   * @param iamAccountId 账户id
   * @param iamAppId 账户应用id
   * @param username 账户名
   * @return 账户名通行证对象
   */
  IamAccountPassport buildUsernamePassport(Long iamAccountId, Long iamAppId, String username);

  /**
   * 创建手机号码账户通行证对象,没有落库.
   *
   * @param iamAccountId 账户id
   * @param iamAppId 账户应用id
   * @param phone 手机号码
   * @return 手机号码账户通行证对象
   */
  IamAccountPassport buildPhonePassport(Long iamAccountId, Long iamAppId, String phone);

  /**
   * 创建微信小程序账户通行证对象,没有落库.
   *
   * @param wxMiniAppId 微信小程序appid
   * @param openId 微信小程序openid
   * @param unionId 微信小程序unionid
   * @return 微信小程序账户通行证对象
   */
  IamAccountPassport buildWxMiniAppPassport(Long iamAccountId, String wxMiniAppId, String openId, String unionId);

  void addOrModifyByUsername(IamAccount iamAccount, String username);
}
